<!DOCTYPE html>
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
	<title>自定义promise</title>
	<style type="text/css">
	* {
		padding: 0;
		margin: 0;
	}
    </style>
</head>
<body>
	<div class="container">
		<h1>自定义promise</h1>
	</div>
	<script src="my-promise.js"></script>
	<script type="text/javascript">
	var p1 = Promise.resolve('aaa');
	var p2 = new Promise((resolve, reject) => {
		reject('p2 error')
	})

	var p3 =  new Promise((resolve, reject) => {
		setTimeout(() => {
			resolve(p2)
		})
	})

	// var p4 = Promise.reject(p3);



	function type (data) {
		return Object.prototype.toString.call(data)
	}

	Promise.reject(p1).then(value => {
		console.log('value => ', value)
	}, reason => {
		console.warn('reason => ', reason);

		console.warn(typeof reason, type(reason), 
		 reason instanceof Promise, reason.constructor.name );

		return reason
	}).then(value => {
		console.log('value2 => ', value)
	}, reason => {
		console.warn('reason2 => ', reason)

	})
    
	</script>
</body>
</html>